home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2586 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: badger.wmin.ac.uk!kruppd
  2. From: kruppd@westminster.ac.uk (Declan Kruppa)
  3. Newsgroups: comp.lang.c
  4. Subject: ? pointer to array of pointers
  5. Date: 22 Jan 1996 16:05:33 GMT
  6. Organization: University of Westminster
  7. Message-ID: <4e0ckd$ht1@badger.wmin.ac.uk>
  8. NNTP-Posting-Host: badger.wmin.ac.uk
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. I am trying to use some routines in "Numerical Recipies in C"
  12. The book gives code for a function char **matrix which allocates
  13. memory for a
  14. a pointer to an array of ponters. If I call this function with
  15. a=matrix(1,10,1,10) it seems to work ok and I can access the elements of 
  16. the array using a[i][j]   . 
  17. However I would like to be able to step through the array using pointer
  18. notation such as *p++ or **p++ . What would be the notation to step through the 10000 elements sequentily using pointer notation. 
  19.  
  20. Also I would like to write the pointer to a file stream like:
  21. File *fp
  22. fp=fopen("FILE","wb");
  23. fwrite(a,1,10000,fp);
  24.  
  25. but when I read back the file it is not at all what I expect. 
  26. I think that *p is a ponter to the rows in the matrix so I would expect it to 
  27. step through every 10th element in the array. I don't know how to access
  28. sequential elements a[1][1], a[1][2] etc using pointer arithmetic or how to 
  29. write it to a file.
  30. Any help appreciated. 
  31.  
  32. Declan Kruppa
  33. University of Westminster
  34.